package cn.dbwork.yacht.utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class ConnectionFactory {
	//获取数据源
	private static DataSource dataSource=new ComboPooledDataSource();
	
	//获取连接
	public static Connection getConnection() {
		try {
			return dataSource.getConnection();
		} catch (SQLException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		return null;
	}
	
	public static void close(Connection connection,PreparedStatement preparedStatement,ResultSet resultSet) {
		
		try {
			if (resultSet !=null) resultSet.close();
			if (preparedStatement !=null) preparedStatement.close();
			if (connection !=null) connection.close();
		} catch (SQLException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
	}
}
